<%@ page session="true" %>

<%
            String usuario = "";
            HttpSession sesionOk = request.getSession();
            if (sesionOk.getAttribute("usuario") != null) {
%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

   <%@page import="java.io.*"%>
   <%@page import="java.sql.Connection"%>
   <%@page import="java.sql.DriverManager"%>
   <%@page import="java.util.HashMap"%>
   <%@page import="java.util.Map"%>
   <%@page import="net.sf.jasperreports.engine.*"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Creacion del documento en PDF</title>
    </head>
    <body>
<%
    Connection conn=null;
    try
    {
        Class.forName("com.mysql.jdbc.Driver"); //se carga el driver
        conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/innoxel","root","admin");
        out.print("si se conecto");
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }

    File reportFile = new File(application.getRealPath("report1.jasper"));

    Map parameters = new HashMap();

    byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath (),parameters,conn);

    response.setContentType("application/pdf");
    response.setContentLength(bytes.length);
    ServletOutputStream ouputStream = response.getOutputStream();
    ouputStream.write(bytes, 0, bytes.length);
    ouputStream.flush();
    ouputStream.close();
%>

    </body>
</html>
<%            } else {
%>
<jsp:forward page="index.jsp" />
<%                            }
%>